package br.com.center.loja.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import br.com.center.loja.SessionCounter;

@WebListener
public class SessionCounterListener 
					implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		SessionCounter counter = SessionCounter.getInstance();
		
		synchronized (counter) {
			counter.increment();
		}
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		SessionCounter counter = SessionCounter.getInstance();
		
		synchronized (counter) {
			counter.decrement();
		}
	}

}
